cmake_minimum_required(VERSION 2.8.0)
project(caros_leapmotion)

# FIND LEAP SDK
if ( NOT DEFINED LEAPSDK_DIR)
    set(LEAPSDK_DIR "$ENV{LEAPSDK_DIR}") 
endif()
if (DEFINED LEAPSDK_DIR)
    set(LEAP_INCLUDE_DIR "${LEAPSDK_DIR}/include")
    set(LEAP_LIBRARY_DIR "${LEAPSDK_DIR}/lib/x64")

    elseif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/leap/version.txt")
    set(LEAP_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/leap/include")
    set(LEAP_LIBRARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/leap/lib/x64")

    elseif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/LeapSDK/version.txt")
    set(LEAP_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/LeapSDK/include")
    set(LEAP_LIBRARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/LeapSDK/lib/x64")

else()
    set(LEAP_INCLUDE_DIR)
    set(LEAP_LIBRARY_DIR)

endif()

if(EXISTS "${LEAP_LIBRARY_DIR}")
    set(node_name "${PROJECT_NAME}_node")
    # ##############################################################################################
    # Make use of c++11
    # ##############################################################################################
    include("cmake/use-c++11.cmake")

    if(${PROJECT_NAME}_BUILD_TESTS)
        set(
            CMAKE_CXX_FLAGS
            "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wno-unused-variable -Wno-old-style-cast -Wcast-align -Woverloaded-virtual -g -fopenmp -openmp -std=c++1y"
        )
    endif()

    # ##############################################################################################
    # Catkin Packages
    # ##############################################################################################
    find_package(
        catkin REQUIRED
        COMPONENTS caros_common caros_sensor_msgs geometry_msgs roscpp roslint
    )

    find_package(OpenCV REQUIRED)

    # ##############################################################################################
    # Roslint
    # ##############################################################################################
    set(ROSLINT_CPP_OPTS "--filter=-legal/copyright,-runtime/references")
    roslint_cpp()

    # ##############################################################################################
    # catkin specific configuration ##
    # ##############################################################################################
    catkin_package(
        INCLUDE_DIRS include
        CATKIN_DEPENDS caros_common caros_sensor_msgs geometry_msgs roscpp
    )

    include_directories(include ${ROBWORK_INCLUDE_DIR} ${catkin_INCLUDE_DIRS} ${LEAP_INCLUDE_DIR})
    find_library(LIBLEAP Leap NO_DEFAULT_PATH PATHS ${LEAP_LIBRARY_DIR})
 
    add_executable(
        ${PROJECT_NAME}_node
        include/caros/hand_detection/camera_processing.h
        include/caros/hand_detection/global.h
        include/caros/hand_detection/kernels.h
        include/caros/hand_detection/leap_hand_processing.h
        include/caros/leap_motion_node.h
        src/camera_processing.cpp
        src/leap_hand_processing.cpp
        src/leap_motion_node.cpp
        src/main.cpp
    )

    target_link_libraries(${PROJECT_NAME}_node ${ROBWORK_LIBRARIES} ${OpenCV_LIBRARIES}
                          ${catkin_LIBRARIES} ${LIBLEAP})
    message("-- Successully built project --")
else()
    message(
        WARNING
            "caros_leapmotion NOT installed\n" "Install Leap Motion SDK\n"
            "https://developer.leapmotion.com/sdk/v2\n" "put the leap dir in src\n"
    )
endif()
